<?php

session_start();

if (isset($_SESSION['error_msg'])) {
  if (! empty($_SESSION['error_msg']) ) {
    $error_msg = $_SESSION['error_msg'];
  }
}

if ( isset($_SESSION['username']) )              { $username              = $_SESSION['username']; }
if ( isset($_SESSION['affiliation']) )           { $affiliation           = $_SESSION['affiliation']; }
if ( isset($_SESSION['title']) )                 { $title                 = $_SESSION['title']; }
if ( isset($_SESSION['telephone']) )             { $telephone             = $_SESSION['telephone']; }
if ( isset($_SESSION['email']) )                 { $email                 = $_SESSION['email']; }
if ( isset($_SESSION['division']) )              { $division              = $_SESSION['division']; }
if ( isset($_SESSION['other_division']) )        { $other_division        = $_SESSION['other_division']; }
if ( isset($_SESSION['lunch_time']) )            { $lunch_time            = $_SESSION['lunch_time']; }
if ( isset($_SESSION['is_vegetarian']) )         { $is_vegetarian         = $_SESSION['is_vegetarian']; }
if ( isset($_SESSION['notes']) )                 { $notes                 = $_SESSION['notes']; }
if ( isset($_SESSION['needDisabledAccess']) )    { $needDisabledAccess    = $_SESSION['needDisabledAccess']; }
if ( isset($_SESSION['participateSubmission']) ) { $participateSubmission = $_SESSION['participateSubmission']; }

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="style.css" type="text/css" />
  <title>第四十八屆台灣心理學年會報名系統</title>
</head>

<body>
  <div id="container">
    <div id="header">
      <h1>我要<span class="h1_span">報名</span></h1>
    </div>

    <?php if (isset($error_msg)) { echo "<p class=\"error\">" . $error_msg . "</p>"; } ?>
	
    <div id="registration_form">
      <form action="do_register.php" method="post">
      <fieldset>
      <legend>個人資訊</legend>
      <p>
        <label>姓名：（必填）</label><br />
        <?php
          if (isset($username)) {
            if (strcmp($username, "") != 0) {
              echo "<input type=\"text\" name=\"username\" value=\"" . $username . "\" />\n";
            } else {
              echo "<input type=\"text\" name=\"username\" />\n";
            }
          }
          else {
            echo "<input type=\"text\" name=\"username\" />\n";
          }
        ?>
      </p>
      <p>
        <label>單位：（必填）</label><br />
        <?php
          if (isset($affiliation)) {
            if (strcmp($affiliation, "") != 0) {
              echo "<input type=\"text\" name=\"affiliation\" value=\"" . $affiliation . "\" />\n";
            } else {
              echo "<input type=\"text\" name=\"affiliation\" />\n";
            }
          }
          else {
            echo "<input type=\"text\" name=\"affiliation\" />\n";
          }
        ?>
      </p>
      <p>
        <label>職稱：</label><br />
        <?php
          if (isset($title)) {
            if (strcmp($title, "") != 0) {
              echo "<input type=\"text\" name=\"title\" value=\"" . $title . "\" />\n";
            } else {
              echo "<input type=\"text\" name=\"title\" />\n";
            }
          }
          else {
            echo "<input type=\"text\" name=\"title\" />\n";
          }
        ?>
      </p>
      <p>
        <label>聯絡電話：</label><br />
        <?php
          if (isset($telephone)) {
            if (strcmp($telephone, "") != 0) {
              echo "<input type=\"text\" name=\"telephone\" value=\"" . $telephone . "\" /> 09XXXXXXXX 或 0X-XXXXXXX\n";
            } else {
              echo "<input type=\"text\" name=\"telephone\" /> 09XXXXXXXX 或 0X-XXXXXXX\n";
            }
          }
          else {
            echo "<input type=\"text\" name=\"telephone\" /> 09XXXXXXXX 或 0X-XXXXXXX\n";
          }
        ?>
      </p>
      <p>
        <label>電子郵件：（必填）</label><br />
        <?php
          if (isset($email)) {
            if (strcmp($email, "") != 0) {
              echo "<input type=\"text\" name=\"email\" value=\"" . $email . "\" />\n";
            } else {
              echo "<input type=\"text\" name=\"email\" />\n";
            }
          }
          else {
            echo "<input type=\"text\" name=\"email\" />\n";
          }
        ?>
      </p>
      <p>
        <label>參加組別：（必填）</label><br />
        <?php
          if (isset($division)) {
            if (strcmp($division, 'cognitive') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"cognitive\" checked=\"checked\" />認知\n";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"cognitive\" />認知\n";
            }
            if (strcmp($division, 'educational') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"educational\" checked=\"checked\" />教心\n";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"educational\" />教心\n";
            }
            if (strcmp($division, 'io') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"io\" checked=\"checked\" />工商\n";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"io\" />工商\n";
            }
            if (strcmp($division, 'social') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"social\" checked=\"checked\" />社心人格\n";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"social\" />社心人格\n";
            }
            if (strcmp($division, 'clinical') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"clinical\" checked=\"checked\" />臨床諮商\n";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"clinical\" />臨床諮商\n";
            }
            if (strcmp($division, 'psychometric') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"psychometric\" checked=\"checked\" />計量\n";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"psychometric\" />計量\n";
            }
            if (strcmp($division, 'developmental') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"developmental\" checked=\"checked\" />發展\n";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"developmental\" />發展\n";
            }
            if (strcmp($division, 'biological') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"biological\" checked=\"checked\" />生心\n<br />";
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"biological\" />生心\n<br />";
            }
            if (strcmp($division, 'other') == 0) {
              echo "<input type=\"radio\" name=\"division\" value=\"other\" checked=\"checked\" />其他\n";
              if (isset($other_division)) {
                echo "<input type=\"text\" name=\"other_division\" value=\"" . $other_division . "\" />（請註明組別）";
              }
              else {
                echo "<input type=\"text\" name=\"other_division\" />（請註明組別）\n";
              }
            } else {
              echo "<input type=\"radio\" name=\"division\" value=\"other\" />其他\n
                    <input type=\"text\" name=\"other_division\" />（請註明組別）\n";
            }
          } else {
            echo "<input type=\"radio\" name=\"division\" value=\"cognitive\" />認知\n
                  <input type=\"radio\" name=\"division\" value=\"educational\" />教心\n
                  <input type=\"radio\" name=\"division\" value=\"io\" />工商\n
                  <input type=\"radio\" name=\"division\" value=\"social\" />社心人格\n
                  <input type=\"radio\" name=\"division\" value=\"clinical\" />臨床諮商\n
                  <input type=\"radio\" name=\"division\" value=\"psychometric\" />計量\n
                  <input type=\"radio\" name=\"division\" value=\"developmental\" />發展\n
                  <input type=\"radio\" name=\"division\" value=\"biological\" />生心\n<br />
                  <input type=\"radio\" name=\"division\" value=\"other\" />其他\n
                  <input type=\"text\" name=\"other_division\" />（請註明組別）\n";
          }
        ?>
      </p>
      </fieldset>
   		  
      <br />
		    
      <fieldset>
      <legend>午餐資訊（不用餐者免填）</legend>
      <p>
        <label>用餐時段：</label>
        <?php
          if (!is_null($lunch_time)) {
            if (count($lunch_time) == 2) {
              echo "<input type=\"checkbox\" name=\"lunch_time[]\" value=\"26\" checked=\"checked\" /> 9 月 26 日（六）\n
                    <input type=\"checkbox\" name=\"lunch_time[]\" value=\"27\" checked=\"checked\" /> 9 月 27 日（日）\n";
            }
            if (count($lunch_time) == 1) {
              if (strcmp($lunch_time[0], "26") == 0) {
                echo "<input type=\"checkbox\" name=\"lunch_time[]\" value=\"26\" checked=\"checked\" /> 9 月 26 日（六）\n
                      <input type=\"checkbox\" name=\"lunch_time[]\" value=\"27\" /> 9 月 27 日（日）\n";
              }
              if (strcmp($lunch_time[0], "27") == 0) {
                echo "<input type=\"checkbox\" name=\"lunch_time[]\" value=\"26\" /> 9 月 26 日（六）\n
                      <input type=\"checkbox\" name=\"lunch_time[]\" value=\"27\" checked=\"checked\" /> 9 月 27 日（日）\n";
              }
              if (strcmp($lunch_time[0], "26") != 0 && strcmp($lunch_time[0], "27") != 0) {
                echo "<input type=\"checkbox\" name=\"lunch_time[]\" value=\"26\" /> 9 月 26 日（六）\n
                      <input type=\"checkbox\" name=\"lunch_time[]\" value=\"27\" /> 9 月 27 日（日）\n";
              }
            }
          }
          else {
            echo "<input type=\"checkbox\" name=\"lunch_time[]\" value=\"26\" /> 9 月 26 日（六）\n
                  <input type=\"checkbox\" name=\"lunch_time[]\" value=\"27\" /> 9 月 27 日（日）\n";
          }
        ?>
      </p>
      <p>
        <label>用餐習慣：</label>
        <?php
          if (isset($is_vegetarian)) {
            if (strcmp($is_vegetarian, "0") == 0) {
              echo "<input type=\"radio\" name=\"is_vegetarian\" value=\"0\" checked=\"checked\" />葷素不拘\n
                    <input type=\"radio\" name=\"is_vegetarian\" value=\"1\" />素食\n";
            }
            if (strcmp($is_vegetarian, "1") == 0) {
              echo "<input type=\"radio\" name=\"is_vegetarian\" value=\"0\" />葷素不拘\n
                    <input type=\"radio\" name=\"is_vegetarian\" value=\"1\"  checked=\"checked\" />素食\n";
            }
            if (strcmp($is_vegetarian, "0") != 0 && strcmp($is_vegetarian, "1") != 0) {
              echo "<input type=\"radio\" name=\"is_vegetarian\" value=\"0\" />葷素不拘\n
                    <input type=\"radio\" name=\"is_vegetarian\" value=\"1\" />素食\n";
            }
          } else {
            echo "<input type=\"radio\" name=\"is_vegetarian\" value=\"0\" />葷素不拘\n
                  <input type=\"radio\" name=\"is_vegetarian\" value=\"1\" />素食\n";
          }
        ?>
      </p>
      <p>
      <label>備註事項：</label><br/>
        <?php
          if (isset($notes)) {
            if (strcmp($notes, "") != 0) {
              echo "<textarea name=\"notes\" rows=\"10\" cols=\"30\">" . $notes . "</textarea>";
            } else {
              echo "<textarea name=\"notes\" rows=\"10\" cols=\"30\"></textarea>";
            }
          }
          else {
            echo "<textarea name=\"notes\" rows=\"10\" cols=\"30\"></textarea>";
          }
        ?>
      </p>
      </fieldset>

      <br />

      <fieldset>
      <legend>其他資訊</legend>
      <p>
        <label>無障礙設施：</label>
        <?php
          if (isset($needDisabledAccess)) {
            if (strcmp($needDisabledAccess, "0") == 0) {
              echo "<input type=\"radio\" name=\"needDisabledAccess\" value=\"0\" checked=\"checked\" />不需要\n
                    <input type=\"radio\" name=\"needDisabledAccess\" value=\"1\" />需要\n";
            }
            if (strcmp($needDisabledAccess, "1") == 0) {
              echo "<input type=\"radio\" name=\"needDisabledAccess\" value=\"0\" />不需要\n
                    <input type=\"radio\" name=\"needDisabledAccess\" value=\"1\" checked=\"checked\" />需要\n";
            }
            if (strcmp($needDisabledAccess, "0") != 0 && strcmp($needDisabledAccess, "1") != 0) {
              echo "<input type=\"radio\" name=\"needDisabledAccess\" value=\"0\" />不需要\n
                    <input type=\"radio\" name=\"needDisabledAccess\" value=\"1\" />需要\n";
            }
          } else {
            echo "<input type=\"radio\" name=\"needDisabledAccess\" value=\"0\" />不需要\n
                  <input type=\"radio\" name=\"needDisabledAccess\" value=\"1\" />需要\n";
          }
        ?>
      </p>
      <p>
        <label>是否參加投稿：</label>
        <?php
          if (isset($participateSubmission)) {
            if (strcmp($participateSubmission, "1") == 0) {
              echo "<input type=\"radio\" name=\"participateSubmission\" value=\"1\" checked=\"checked\" />是\n
                    <input type=\"radio\" name=\"participateSubmission\" value=\"0\" />否\n";
            }
            if (strcmp($participateSubmission, "0") == 0) {
              echo "<input type=\"radio\" name=\"participateSubmission\" value=\"1\" />是\n
                    <input type=\"radio\" name=\"participateSubmission\" value=\"0\" checked=\"checked\" />否\n";
            }
            if (strcmp($participateSubmission, "0") != 0 && strcmp($participateSubmission, "1") != 0) {
              echo "<input type=\"radio\" name=\"participateSubmission\" value=\"1\" />是\n
                    <input type=\"radio\" name=\"participateSubmission\" value=\"0\" />否\n";
            }
          } else {
            echo "<input type=\"radio\" name=\"participateSubmission\" value=\"1\" />是\n
                  <input type=\"radio\" name=\"participateSubmission\" value=\"0\" />否\n";
          }
        ?>
      </p>
      </fieldset>

      <br />

      <p>
        <input type="submit" name="submit" value="送出" />
      </p>
      </form>
    </div>

    <div id="footer">
      <p>&copy; 2009 第四十八屆台灣心理學年會</p>
    </div>

  </div>
</body>
</html>